<template>
	<view>
		<u-sticky bgColor="#f8f8f8">
			<view class="" style="padding: 30rpx 30rpx 0;">
				<view class="con__box">
					<image src="/static/points/boxbg.png" class="con__box__bg" mode=""></image>

					<view class="con__box__c">
						<view class="">
							<view class="con__box__t">
								当前积分最低售价
							</view>
							<view class="con__box__num">
								<view class="con__box__tip">
									10积分等于
								</view>
								<view style="color: #E3432D;">
									<text style="font-size: 28rpx;">￥</text>1
								</view>
							</view>
						</view>
						<image src="/static/task/hb.png" class="con__box__hb" mode=""></image>
					</view>
				</view>
			</view>
		</u-sticky>
		<view class="con">

			<view class="con__item" v-for="(item,index) in list" :key="index">
				<image src="/static/points/icon.png" class="con__item__icon" mode=""></image>
				<view class="" style="flex: 1;">
					<view class="con__item__name">
						{{item.user_name}}
					</view>
					<view class="con__item__time">
						10积分=
						<text style="color: #E3432D;font-size: 36rpx;">
							<text style="font-size: 24rpx;">￥</text>{{item.price}}
						</text>
					</view>
				</view>
				<view class="">
					<view class="con__item__jf" style="margin-bottom: 10rpx;">
						库存:{{item.num}}积分
					</view>
					<u-button :customStyle="{width:'131rpx',height:'52rpx',padding:0,fontSie:'24rpx',margin:'0',}"
						shape='circle' color="#E3432D" text="购买" @click="choose(item)"></u-button>
				</view>
			</view>

		</view>
		<!-- 		<u-modal :show="show1" :title="title" :show-cancel-button="true" @cancel="show1=false" @confirm="confirm">
			<view class="slot-content" style="color: #E3432D;">
				<text style="font-size: 26rpx;">￥</text>
				<text style="font-size: 60rpx;">100</text>
			</view>
		</u-modal> -->
		<u-popup mode="bottom" :show="show" round="30rpx" @close="show=false">
			<view class="popbox">
				<view class="" style="padding: 0 30rpx;">
					<view class="popbox__info">
						<view class="u-flex u-flex-y-center">
							<image :src="info.avatar?info.avatar:'/static/goods/tx.png'" class="popbox__info__pic"
								mode="aspectFill">
								<view class="">
									<view class="popbox__info__name">
										10积分
									</view>
									<view class="popbox__info__price">
										{{info.price}}
									</view>
									<u-number-box v-model="num">
										<view slot="minus" class="minus">
											<u-icon name="minus" size="24rpx" color="#6a6a6a"></u-icon>
										</view>
										<text slot="input"
											style="width: 78rpx;text-align: center;font-size: 30rpx;background-color: #F2F6F9;height: 48rpx;margin: 0 2rpx;"
											class="input">{{num}}</text>
										<view slot="plus" class="plus">
											<u-icon name="plus" color="#6a6a6a" size="24rpx"></u-icon>
										</view>
									</u-number-box>
								</view>
						</view>
					</view>
				</view>
				<u-gap bgColor="#F7F7F9" height="18rpx"></u-gap>

				<u-radio-group v-model="value" iconPlacement="right" placement='column'>
					<u-radio activeColor="#FF4D30"
						:customStyle="{paddingRight: '30rpx',width:'720rpx',backgroundColor:value==item.name?'rgba(255, 77, 48, .05)':''}"
						v-for="(item, index) in radiolist1" :key="index" :name="item.name" @change="radioChange">
						<view class="popbox__pay">
							<image :src="'/static/goods/'+item.icon+'.png'" class="popbox__pay__icon" mode=""></image>
							<view class="popbox__pay__label">
								{{item.name}} <text v-if="item.name=='余额支付'">({{userInfo.money}})</text>
							</view>
						</view>
					</u-radio>
				</u-radio-group>
				<view class="popbox__footer">
					<u-button :text="'确认支付(￥'+ Number(info.price)*num +')'" color="#FF4D30" shape='circle' size="large"
						@click="submit"></u-button>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import {
		scoregoodlist,
		buyscore
	} from "@/request/api/sell.js"
	import {
		userInfo,
	} from "@/request/api/my.js"
	export default {
		data() {
			return {
				val: 0,
				list: [],
				show: false,
				show1: false,
				title: "需支付",
				num: 1,

				money: 10,
				value: '微信支付',
				radiolist1: [{
						name: '微信支付',
						icon: 'wx'
					},
					{
						name: '余额支付',
						icon: 'ye'
					},
				],

				userInfo: {
					money: 0,
				},

				info: {

				},
				timer: null
			};
		},
		onShow() {
			scoregoodlist().then(res => {
				this.list = res.data;
			})
			userInfo().then(res => {
				this.userInfo = res.data;
			})
		},
		onLoad() {

		},
		beforeDestroy() {
			// this.timer = setInterval(()=>{

			// },1000)
		},
		methods: {
			radioChange(n) {
				this.value = n
			},
			confirm() {

			},
			choose(item) {
				this.info = item;
				this.show = true
			},
			submit() {
				let paytype = this.value == '微信支付' ? 2 : 1;
				if (paytype == 1) {
					if (Number(this.info.price) * this.num > Number(this.userInfo.money)) {
						uni.$u.toast('余额不足');
						return
					}
				}

				buyscore({
					num: this.num * 10,
					id: this.info.id,
					pay_type: paytype,
					total_price: Number(this.info.price) * this.num
				}).then(res1 => {
					scoregoodlist().then(res => {
						this.list = res.data;
					})
					userInfo().then(res => {
						this.userInfo = res.data;
					})
					this.show = false;
				})
			}
		}
	}
</script>

<style lang="scss">
	.con {
		padding: 30rpx;

		&__box {
			width: 690rpx;
			height: 182rpx;
			position: relative;

			&__bg {
				width: 690rpx;
				height: 182rpx;
				position: absolute;
				top: 0;
				left: 0;
			}

			&__c {
				width: 690rpx;
				height: 182rpx;
				position: absolute;
				top: 0;
				left: 0;
				display: flex;
				align-items: center;
				justify-content: space-between;
			}

			&__hb {
				width: 142rpx;
				height: 160rpx;
				margin-right: 48rpx;
			}

			&__t {
				font-family: PingFang-SC, PingFang-SC;
				font-weight: bold;
				font-size: 24rpx;
				color: #000000;
				line-height: 24rpx;
				margin: 30rpx 0 16rpx 37rpx;
			}

			&__num {
				font-family: DINNextLTPro;
				font-weight: bold;
				font-size: 68rpx;
				color: #000000;
				margin-left: 37rpx;
				display: flex;
				align-items: flex-end;
			}

			&__tip {
				font-family: PingFang-SC-Regular;
				font-size: 24rpx;
				font-weight: normal;
				margin-bottom: 20rpx;
				margin-left: 10rpx;
			}
		}

		&__item {
			display: flex;
			align-items: center;
			padding: 43rpx 22rpx 28rpx 27rpx;
			background: #FFFFFF;
			border-radius: 30rpx 30rpx 30rpx 30rpx;
			margin-bottom: 27rpx;

			&__icon {
				width: 90rpx;
				height: 90rpx;
				margin-right: 18rpx;
			}

			&__name {
				font-family: PingFang-SC, PingFang-SC;
				font-weight: bold;
				font-size: 28rpx;
				color: #1E1E1E;
				line-height: 28rpx;
				margin-bottom: 23rpx;
			}

			&__time {
				font-family: DINNextLTPro;
				font-weight: 500;
				font-size: 25rpx;
				color: #929292;
				line-height: 25rpx;
			}

			&__jf {
				font-family: PingFang-SC, PingFang-SC;
				font-weight: 500;
				font-size: 24rpx;
				color: #E3432D;
				line-height: 24rpx;
				display: flex;
			}

			&__num {
				font-family: DINNextLTPro;
				font-weight: 500;
				font-size: 31rpx;
				color: #E3432D;
				line-height: 31rpx;
			}
		}
	}

	.popbox {
		height: 90vh;
		position: relative;


		&__addrbox {
			height: 142rpx;
			display: flex;
			align-items: center;
			border-bottom: 1rpx solid #E9EAEC;

			&__icon {
				width: 36rpx;
				height: 40rpx;
				margin-right: 16rpx;
			}

			&__addr {
				font-family: PingFang-SC, PingFang-SC;
				font-weight: bold;
				font-size: 30rpx;
				color: #232323;
				line-height: 46rpx;
			}

			&__name {
				font-family: PingFang-SC, PingFang-SC;
				font-weight: 500;
				font-size: 26rpx;
				color: #747474;
				line-height: 46rpx;
			}
		}

		&__info {
			padding: 40rpx 0;

			&__pic {
				width: 178rpx;
				height: 177rpx;
				background: #42C03D;
				border-radius: 20rpx 20rpx 20rpx 20rpx;
				margin-right: 24rpx;
			}

			&__name {
				font-family: PingFang-SC, PingFang-SC;
				font-weight: 800;
				font-size: 33rpx;
				color: #181818;
				line-height: 33rpx;
				margin: 5rpx 0 17rpx;
			}

			&__price {
				font-family: DINNextLTPro;
				font-weight: 500;
				font-size: 43rpx;
				color: #FF4D30;
				line-height: 43rpx;
				margin-bottom: 30rpx;

				&::before {
					content: "￥";
					font-family: PingFang-SC, PingFang-SC;
					font-weight: 800;
					font-size: 28rpx;
					color: #FF4D30;
					line-height: 43rpx;
				}
			}

			.minus,
			.plus {
				width: 48rpx;
				height: 48rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				color: #111A2B;
				background-color: #F2F6F9;
			}

			.minus {
				border-radius: 10rpx 0 0 10rpx;
			}

			.plus {
				border-radius: 0 10rpx 10rpx 0;
			}
		}

		&__title {
			font-family: PingFang-SC, PingFang-SC;
			font-weight: bold;
			font-size: 30rpx;
			color: #0A1122;
			line-height: 30rpx;
			margin-top: 47rpx;
			margin-bottom: 33rpx;
		}

		&__fl {
			width: 690rpx;
			margin-bottom: 63rpx;

			&__list {
				display: flex;
				align-items: center;
			}

			&__item {
				height: 58rpx;
				background: #F2F6F9;
				border-radius: 10rpx 10rpx 10rpx 10rpx;
				overflow: hidden;
				display: flex;
				align-items: center;
				border: 1rpx solid #ffffff;
				margin-right: 16rpx;
				flex-shrink: 0;

				&__p {
					width: 58rpx;
					height: 58rpx;
					background: #42C03D;
				}

				&__name {
					padding: 0 22rpx;
					background-color: #F2F6F9;
					display: flex;
					align-items: center;
					font-family: PingFang-SC, PingFang-SC;
					font-weight: bold;
					font-size: 26rpx;
					color: #0A1122;
					line-height: 26rpx;
				}
			}

			.active {
				border-color: #e3432d;
			}
		}

		&__bz {
			font-family: PingFang-SC, PingFang-SC;
			font-weight: 500;
			font-size: 26rpx;
			color: #141F32;
			line-height: 26rpx;
			display: flex;
			align-items: center;
		}

		&__pay {
			padding: 30rpx 0 30rpx 30rpx;
			display: flex;
			align-items: center;

			&__icon {
				width: 41rpx;
				height: 41rpx;
				margin-right: 20rpx;
			}

			&__label {
				font-family: PingFang-SC, PingFang-SC;
				font-weight: 500;
				font-size: 27rpx;
				color: #010000;
				line-height: 27rpx;
				flex: 1;
			}
		}

		&__footer {
			padding: 47rpx 18rpx 47rpx 43rpx;
			width: 689rpx;
			position: absolute;
			bottom: 0;
			left: 0;
		}
	}
</style>